package com.hua.demo02;


import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;

public class TestRunable implements Runnable{
    private String url;
    private String name;
    public TestRunable(String url,String name){
        this.name = name;
        this.url = url;
    }


    @Override
    public void run() {
        WebDownLoader webDownLoader = new WebDownLoader();
        webDownLoader.downloader(url,name);
        System.out.println("下载文件名为："+name);
    }

    public static void main(String[] args) {
        TestRunable testRunable = new TestRunable("http://sc.cltt.org/Web/common/GeneratePhotoByStuID.ashx?StuID=5101621120079", "1.jpg");
        new Thread(testRunable).start();

    }



}
//下载器
class WebDownLoader {

    public void downloader(String url, String name) {
        try {
            FileUtils.copyURLToFile(new URL(url),
                    new File(name));
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("IO异常,downloader方法出现问题");
        }

    }
}